package my.test.csdn.weixin_43767015.basic.ch12.transaction.declarative.annotation.propagation.never.base.service;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TxNeverService {
    /**
     * jdbc模版，用于操作数据库
     */
    @Resource
    private JdbcTemplate jdbcTemplate;

    /** 单独调用m2 */
	@Transactional(propagation = Propagation.NEVER)
    public void m2() {
        String sql = "insert into tx_study (name,age) values (?,?)";
        jdbcTemplate.update(sql, "TxNever", 30);
        //抛出一个RuntimeException
        throw new RuntimeException();
	}
	
	/** 相当于不开启任何事务，当作普通方法运行 */
	public void tran() {
	    //单独调用m2，相当于不开启事务
	    m2();
	}    
}
